import datetime

from django.db import models
from django.urls import reverse


# Create your models here.

class Album(models.Model):
    album_title = models.CharField(max_length=500)
    description = models.TextField()
    image = models.ImageField(upload_to='albums/')
    date_created = models.DateTimeField(auto_now_add=True)
    download_count = models.IntegerField(default=0)

    def __str__(self):
        return self.album_title

    def get_absolute_url(self):
        return reverse('index')

    def get_img_size(self):
        # 获取图片长和宽
        from PIL import Image
        img = Image.open(self.image.path)
        return img.size


